#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "./CustomClass/QProjectTreeWidget.h"
#include "./Project/NewDeviceDialog.h"
#include "./Project/NewUpdateChannelDialog.h"
#include "./attrib/CollectChannelCountForm.h"
#include "./attrib/CollectChannlForm.h"
#include "./attrib/CollectDeivceForm.h"
#include "./attrib/ProjectAttribForm.h"
#include "./attrib/UpdateChannelCountForm.h"
#include "./attrib/UpdateChannelForm.h"
#include "./tool/UploadProjectDialog.h"
#include "SARibbonBar.h"
#include "SARibbonMainWindow.h"
#include "pugixml/pugixml.hpp"
#include <QMainWindow>
#include <QPluginLoader>

namespace Ui {
class MainWindow;
}

class MainWindow : public SARibbonMainWindow {
  Q_OBJECT

public:
  explicit MainWindow(QWidget *parent = nullptr);
  ~MainWindow();
  enum QActionUserType {
    Action_New_Project,
    Action_Open_Project,
    Action_SaveAS_Project,
    Action_Delete_Project,
    Action_View_Project,
    Action_Save_Project,
    Action_New_CollectChannel,
    Action_Del_CollectChannel,
    Action_New_CollectDevice,
    Action_Del_CollectDevice,
    Action_Cpy_CollectDevice,
    Action_New_UpdateChannel,
    Action_Del_UpdateChannel,
    Action_Cpy_UpdateChannel,
    Action_Upload_Project,
    Action_Down_Project,
    ACtion_View_RTBase,
    Action_System_Close,
    Action_System_Help,
  };

private:
  void initApplicationMenu();
  void initToolboorProject();
  void changeAttrobPage(QWidget *currentWidget = nullptr);
  QAction *createAction(const QString &text, const QString &iconurl,
                        QActionUserType userData, bool connectSlot = false);
private slots:
  void customContextMenuRequested(const QPoint &pos);
  void slot_on_actionTriggered();
  void tree_clicked(QTreeWidgetItem *current, QTreeWidgetItem *previous);

private:
  Ui::MainWindow *ui;
  QMenu *mMenuApplicationBtn{nullptr};
  QMenu *m_menuProject{nullptr};
  QMenu *m_menuCollectChannel{nullptr};
  QMenu *m_menuCollectDevice{nullptr};
  QMenu *m_menuCollectDeleteCp{nullptr}; //采集设备

  QMenu *m_menuUpdateChannel{nullptr};
  QMenu *m_menuUpdateOperate{nullptr};

  QMenu *m_menuOpenProjectChild{nullptr};
  QProjectTreeWidget *m_projectTreeWidget{nullptr};

  QStringList GetLastOpenListFile();
  bool wirteLastOpenFile(QString fileName);

private:
  ProjectAttribForm *m_projectAttribForm;
  AttribBaseForm *m_collectChannelForm;
  AttribBaseForm *m_collectDeviceForm;
  CollectChannelCountForm *m_collectCountForm;

  UpdateChannelCountForm *m_updateCountForm;
  AttribBaseForm *m_updateChannelForm;
  QAction *m_lastOpenAction;
};

#endif // MAINWINDOW_H
